﻿using System;
using SEXY;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x02000555 RID: 1365
	[Serializable]
	public class UI_ColorSlider : UI_ColorPresets
	{
		// Token: 0x060022D1 RID: 8913 RVA: 0x000D2344 File Offset: 0x000D0544
		protected override void Init()
		{
			base.Init();
			for (int i = 0; i < 3; i++)
			{
				if (this.imgSlider[i])
				{
					this.texSlider[i] = (this.imgSlider[i].mainTexture as Texture2D);
					this.texSliderSize[i].x = (float)this.texSlider[i].width;
					this.texSliderSize[i].y = (float)this.texSlider[i].height;
				}
			}
			if (this.tfSliderMode[(int)this.sliderMode])
			{
				Toggle component = this.tfSliderMode[(int)this.sliderMode].GetComponent<Toggle>();
				if (component)
				{
					component.isOn = true;
				}
			}
			this.ChangeSliderMode();
		}

		// Token: 0x060022D2 RID: 8914 RVA: 0x000D2418 File Offset: 0x000D0618
		public void ChangeSliderMode(UI_Parameter param)
		{
			if (null == param)
			{
				return;
			}
			Toggle component = param.GetComponent<Toggle>();
			if (component && component.isOn)
			{
				UI_ColorSlider.SliderMode sliderMode = (UI_ColorSlider.SliderMode)Enum.ToObject(typeof(UI_ColorSlider.SliderMode), param.index);
				if (this.sliderMode == sliderMode)
				{
					return;
				}
				this.sliderMode = sliderMode;
				this.ChangeSliderMode();
			}
		}

		// Token: 0x060022D3 RID: 8915 RVA: 0x000D2484 File Offset: 0x000D0684
		public void ChangeSliderMode()
		{
			if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				if (this.labelSlider[0])
				{
					this.labelSlider[0].text = "Ｒ";
				}
				if (this.labelSlider[1])
				{
					this.labelSlider[1].text = "Ｇ";
				}
				if (this.labelSlider[2])
				{
					this.labelSlider[2].text = "Ｂ";
				}
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				if (this.labelSlider[0])
				{
					this.labelSlider[0].text = "色合い";
				}
				if (this.labelSlider[1])
				{
					this.labelSlider[1].text = "鮮やかさ";
				}
				if (this.labelSlider[2])
				{
					this.labelSlider[2].text = "明るさ";
				}
			}
			this.disableSetColor = true;
			this.ChangeSliderSliderPos(0);
			this.ChangeSliderSliderPos(1);
			this.ChangeSliderSliderPos(2);
			this.ChangeSliderSliderPos(3);
			this.ChangeSliderSliderText(0);
			this.ChangeSliderSliderText(1);
			this.ChangeSliderSliderText(2);
			this.ChangeSliderSliderText(3);
			this.ChangeSliderSliderColor(0);
			this.ChangeSliderSliderColor(1);
			this.ChangeSliderSliderColor(2);
			this.disableSetColor = false;
		}

		// Token: 0x060022D4 RID: 8916 RVA: 0x000D25E0 File Offset: 0x000D07E0
		public void OnChangeSliderSliderValue01(float value)
		{
			if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				HsvColor colorHSV = base.GetColorHSV();
				colorHSV.H = value * 360f;
				base.SetColor(colorHSV, UI_ColorInfo.ControlType.SliderColor01);
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				Color colorRGB = base.GetColorRGB();
				colorRGB.r = value;
				base.SetColor(colorRGB, UI_ColorInfo.ControlType.SliderColor01);
			}
		}

		// Token: 0x060022D5 RID: 8917 RVA: 0x000D263C File Offset: 0x000D083C
		public void OnChangeSliderSliderValue02(float value)
		{
			if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				HsvColor colorHSV = base.GetColorHSV();
				colorHSV.S = value;
				base.SetColor(colorHSV, UI_ColorInfo.ControlType.SliderColor02);
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				Color colorRGB = base.GetColorRGB();
				colorRGB.g = value;
				base.SetColor(colorRGB, UI_ColorInfo.ControlType.SliderColor02);
			}
		}

		// Token: 0x060022D6 RID: 8918 RVA: 0x000D2694 File Offset: 0x000D0894
		public void OnChangeSliderSliderValue03(float value)
		{
			if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				HsvColor colorHSV = base.GetColorHSV();
				colorHSV.V = value;
				base.SetColor(colorHSV, UI_ColorInfo.ControlType.SliderColor03);
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				Color colorRGB = base.GetColorRGB();
				colorRGB.b = value;
				base.SetColor(colorRGB, UI_ColorInfo.ControlType.SliderColor03);
			}
		}

		// Token: 0x060022D7 RID: 8919 RVA: 0x000D26EC File Offset: 0x000D08EC
		public void OnChangeSliderSliderValue04(float value)
		{
			base.SetAlpha(value, UI_ColorInfo.ControlType.SliderAlpha);
		}

		// Token: 0x060022D8 RID: 8920 RVA: 0x000D26F8 File Offset: 0x000D08F8
		public void OnChangeSliderInputValue01(string buf)
		{
			bool flag = false;
			if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				HsvColor colorHSV = base.GetColorHSV();
				float num = base.ConvertValueFromText(UI_ColorInfo.ColorType.Hue, buf, ref flag);
				if (flag)
				{
					this.inputSlider[0].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Hue, num);
				}
				colorHSV.H = num * 360f;
				base.SetColor(colorHSV, UI_ColorInfo.ControlType.InputColor01);
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				Color colorRGB = base.GetColorRGB();
				colorRGB.r = base.ConvertValueFromText(UI_ColorInfo.ColorType.Red, buf, ref flag);
				if (flag)
				{
					this.inputSlider[0].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Red, colorRGB.r);
				}
				base.SetColor(colorRGB, UI_ColorInfo.ControlType.InputColor01);
			}
		}

		// Token: 0x060022D9 RID: 8921 RVA: 0x000D27A8 File Offset: 0x000D09A8
		public void OnChangeSliderInputValue02(string buf)
		{
			bool flag = false;
			if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				HsvColor colorHSV = base.GetColorHSV();
				colorHSV.S = base.ConvertValueFromText(UI_ColorInfo.ColorType.Saturation, buf, ref flag);
				if (flag)
				{
					this.inputSlider[1].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Saturation, colorHSV.S);
				}
				base.SetColor(colorHSV, UI_ColorInfo.ControlType.InputColor02);
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				Color colorRGB = base.GetColorRGB();
				colorRGB.g = base.ConvertValueFromText(UI_ColorInfo.ColorType.Green, buf, ref flag);
				if (flag)
				{
					this.inputSlider[1].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Green, colorRGB.g);
				}
				base.SetColor(colorRGB, UI_ColorInfo.ControlType.InputColor02);
			}
		}

		// Token: 0x060022DA RID: 8922 RVA: 0x000D2854 File Offset: 0x000D0A54
		public void OnChangeSliderInputValue03(string buf)
		{
			bool flag = false;
			if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				HsvColor colorHSV = base.GetColorHSV();
				colorHSV.V = base.ConvertValueFromText(UI_ColorInfo.ColorType.Value, buf, ref flag);
				if (flag)
				{
					this.inputSlider[2].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Value, colorHSV.V);
				}
				base.SetColor(colorHSV, UI_ColorInfo.ControlType.InputColor03);
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				Color colorRGB = base.GetColorRGB();
				colorRGB.b = base.ConvertValueFromText(UI_ColorInfo.ColorType.Blue, buf, ref flag);
				if (flag)
				{
					this.inputSlider[2].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Blue, colorRGB.b);
				}
				base.SetColor(colorRGB, UI_ColorInfo.ControlType.InputColor03);
			}
		}

		// Token: 0x060022DB RID: 8923 RVA: 0x000D2904 File Offset: 0x000D0B04
		public void OnChangeSliderInputValue04(string buf)
		{
			bool flag = false;
			float num = base.ConvertValueFromText(UI_ColorInfo.ColorType.Alpha, buf, ref flag);
			if (flag)
			{
				this.inputSlider[3].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Alpha, num);
			}
			base.SetAlpha(num, UI_ColorInfo.ControlType.InputAlpha);
		}

		// Token: 0x060022DC RID: 8924 RVA: 0x000D2944 File Offset: 0x000D0B44
		public void ChangeSliderSliderColor(int index)
		{
			if (null == this.texSlider[index])
			{
				return;
			}
			int num = (int)this.texSliderSize[index].x;
			int num2 = (int)this.texSliderSize[index].y;
			Color[] array = new Color[num2 * num];
			if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				float[] rateHSV = base.GetRateHSV();
				if (index == 0 || index == 1)
				{
					if (index == 0)
					{
						rateHSV[1] = 1f;
						rateHSV[2] = 1f;
					}
					for (int i = 0; i < num2; i++)
					{
						for (int j = 0; j < num; j++)
						{
							rateHSV[index] = Mathf.InverseLerp(0f, this.texSliderSize[index].x, (float)j);
							array[i * num + j] = HsvColor.ToRgb(rateHSV[0] * 360f, rateHSV[1], rateHSV[2]);
						}
					}
				}
				else
				{
					for (int k = 0; k < num2; k++)
					{
						for (int l = 0; l < num; l++)
						{
							float t = Mathf.InverseLerp(0f, this.texSliderSize[index].x, (float)l);
							Color color = HsvColor.ToRgb(rateHSV[0] * 360f, rateHSV[1], 1f);
							Color color2 = default(Color);
							color2.r = Mathf.Lerp(0f, color.r, t);
							color2.g = Mathf.Lerp(0f, color.g, t);
							color2.b = Mathf.Lerp(0f, color.b, t);
							color2.a = 1f;
							array[k * num + l] = color2;
						}
					}
				}
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				float[] rateRGB = base.GetRateRGB();
				for (int m = 0; m < num2; m++)
				{
					for (int n = 0; n < num; n++)
					{
						rateRGB[index] = Mathf.InverseLerp(0f, this.texSliderSize[index].x, (float)n);
						array[m * num + n] = new Color(rateRGB[0], rateRGB[1], rateRGB[2]);
					}
				}
			}
			this.texSlider[index].SetPixels(array);
			this.texSlider[index].Apply();
		}

		// Token: 0x060022DD RID: 8925 RVA: 0x000D2BC0 File Offset: 0x000D0DC0
		public void ChangeSliderSliderPos(int index)
		{
			if (!MathfEx.RangeEqualOn<int>(0, index, 3))
			{
				return;
			}
			if (null == this.sliderSlider[index])
			{
				return;
			}
			if (index == 3)
			{
				this.sliderSlider[3].value = base.GetColorAlpha();
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				float[] rateHSV = base.GetRateHSV();
				this.sliderSlider[index].value = rateHSV[index];
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				float[] rateRGB = base.GetRateRGB();
				this.sliderSlider[index].value = rateRGB[index];
			}
		}

		// Token: 0x060022DE RID: 8926 RVA: 0x000D2C58 File Offset: 0x000D0E58
		public void ChangeSliderSliderText(int index)
		{
			if (!MathfEx.RangeEqualOn<int>(0, index, 3))
			{
				return;
			}
			if (null == this.inputSlider[index])
			{
				return;
			}
			if (index == 3)
			{
				float colorAlpha = base.GetColorAlpha();
				this.inputSlider[3].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Alpha, colorAlpha);
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeHSV)
			{
				float[] rateHSV = base.GetRateHSV();
				if (index == 0)
				{
					this.inputSlider[0].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Hue, rateHSV[0]);
				}
				else if (index == 1)
				{
					this.inputSlider[1].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Saturation, rateHSV[1]);
				}
				else if (index == 2)
				{
					this.inputSlider[2].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Value, rateHSV[2]);
				}
			}
			else if (this.sliderMode == UI_ColorSlider.SliderMode.ModeRGB)
			{
				float[] rateRGB = base.GetRateRGB();
				if (index == 0)
				{
					this.inputSlider[0].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Red, rateRGB[0]);
				}
				else if (index == 1)
				{
					this.inputSlider[1].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Green, rateRGB[1]);
				}
				else if (index == 2)
				{
					this.inputSlider[2].text = base.ConvertTextFromValue(UI_ColorInfo.ColorType.Blue, rateRGB[2]);
				}
			}
		}

		// Token: 0x040023EC RID: 9196
		public UI_ColorSlider.SliderMode sliderMode;

		// Token: 0x040023ED RID: 9197
		public Transform[] tfSliderMode = new Transform[Enum.GetValues(typeof(UI_ColorSlider.SliderMode)).Length];

		// Token: 0x040023EE RID: 9198
		public Slider[] sliderSlider = new Slider[4];

		// Token: 0x040023EF RID: 9199
		public Image[] imgSlider = new Image[3];

		// Token: 0x040023F0 RID: 9200
		public Text[] labelSlider = new Text[3];

		// Token: 0x040023F1 RID: 9201
		public InputField[] inputSlider = new InputField[4];

		// Token: 0x040023F2 RID: 9202
		private Texture2D[] texSlider = new Texture2D[3];

		// Token: 0x040023F3 RID: 9203
		private Vector2[] texSliderSize = new Vector2[3];

		// Token: 0x02000556 RID: 1366
		public enum SliderMode
		{
			// Token: 0x040023F5 RID: 9205
			ModeHSV,
			// Token: 0x040023F6 RID: 9206
			ModeRGB
		}
	}
}
